package day38.zuoye;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class SumThread {
    public static void main(String[] args) throws InterruptedException, ExecutionException {
        MyCallable myCallable = new MyCallable();
        FutureTask task1 = new FutureTask(myCallable);
        FutureTask task2 = new FutureTask(myCallable);
        FutureTask task3 = new FutureTask(myCallable);

        Thread t1 = new Thread(task1);
        Thread t2 = new Thread(task2);
        Thread t3 = new Thread(task3);
        t1.start();
        t2.start();
        t3.start();
        Thread.sleep(1000);
        int num1 = (int) task1.get();
        int num2 = (int) task1.get();
        int num3 = (int) task1.get();
        int sum = num1 + num2 + num3;
        System.out.println("主线程执行结果为：" + sum);
    }
}

class MyCallable implements Callable {
    private int count = 0;

    @Override
    public Object call() throws Exception {
        count++;
        return count;

    }
}